
import vuex from "vuex"
import Vue from "vue";

Vue.use(vuex)

let defaultCity = "北京"
try{
    if(localStorage.city){
        defaultCity = localStorage.city
    }
}catch(e){

}

export default new vuex.Store({
    state:{
        city:localStorage.city || defaultCity
    },
    // 复杂做法
    // actions:{
    //     changeCity(ctx,city){
    //         ctx.commit("changeCity",city)
    //     }
    // },
    mutations:{
        changeCity(state,city){
            state.city = city;
            localStorage.city = city;
        }
    }
})